<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<script>
    let socket
    if (window.WebSocket) {
        socket = new WebSocket("ws://localhost:6668/xx.do")
        socket.onmessage = function (ev) {
            let element = document.getElementById("resp");
            element.value = element.value + "\n" + ev.data
        }

        socket.onopen = function (ev) {
            alert("开启")
        }
    }
    function send(msg) {
        if (socket.readyState == WebSocket.OPEN) {
            socket.send(msg);
        }
    }
</script>

    <form onsubmit="return false">
        <textarea name ="message", style="height: 300px; width: 300px"> </textarea>
        <input type="button" value="send" onclick="send(this.form.message.value)">

        <textarea id ="resp", style="height: 300px; width: 300px"> </textarea>
    </form>
</body>
</html>
